//
//  CommonNetwork.h
//  Ev_Master
//
//  Created by Evan on 2019/6/26.
//  Copyright © 2019 Evan. All rights reserved.
//

#ifndef CommonNetwork_h
#define CommonNetwork_h

#import "LoginNavigationController.h"
#import "URLHeader.h"
#import "BaseModel.h"
#import "NetworkManager.h"


#define PMTASK_EXPORT_IMP(name, returnType,postUrl) \
+ (NSURLSessionDataTask *)name:(NSMutableDictionary *)dict success:(void(^)(returnType *response,BOOL success))sucOK failture:(void(^)(NSError *error,NSString *strDescription))err\
{\
if(!dict){\
dict = [NSMutableDictionary new];\
}\
\
NSLog(@"请求入参：%@：\n%@",postUrl,dict); \
return [[NetworkManager sharedManager] baseWithUrl:postUrl parameters:dict requestType:YBMNetworkRequestTypePost IsLoading:YES success:^(NSURLSessionDataTask *operation, id responseObject, BOOL success) {\
NSLog(@"返回出参：%@：\n%@",postUrl,responseObject); \
returnType *pModel = [returnType mj_objectWithKeyValues:responseObject];\
if(pModel.code == 2){\
UIViewController *tabView=(UIViewController*)[UIApplication sharedApplication].keyWindow.rootViewController;\
LoginNavigationController *login = [[LoginNavigationController alloc]init];\
[tabView presentViewController:login animated:YES completion:nil];\
}\
sucOK(pModel,success);\
} failture:^(NSError *error,NSString *strMsg) {\
if ([error.domain isEqual: NSURLErrorDomain]) {\
strMsg=@"网络错误";\
}\
err(error,strMsg);\
} ];\
}\

#define PMTASK_EXPORT_IMP_h(name, returnType) \
+ (NSURLSessionDataTask *)name:(NSMutableDictionary *)dict success:(void(^)(returnType *response,BOOL success))sucOK failture:(void(^)(NSError *error,NSString *strDescription))err;\



#define PMTASK_EXPORT_IMP_GET(name, returnType,postUrl) \
+ (NSURLSessionDataTask *)name:(NSMutableDictionary *)dict success:(void(^)(returnType *response,BOOL success))sucOK failture:(void(^)(NSError *error,NSString *strDescription))err\
{\
if(!dict){\
dict = [NSMutableDictionary new];\
}\
\
NSLog(@"请求入参：%@：\n%@",postUrl,dict); \
return [[NetworkManager sharedManager] baseWithUrl:postUrl parameters:dict requestType:YBMNetworkRequestTypeGet IsLoading:YES success:^(NSURLSessionDataTask *operation, id responseObject, BOOL success) {\
NSLog(@"返回出参：%@：\n%@",postUrl,responseObject); \
returnType *pModel = [returnType mj_objectWithKeyValues:responseObject];\
if(pModel.code == 2){\
UIViewController *tabView=(UIViewController*)[UIApplication sharedApplication].keyWindow.rootViewController;\
LoginNavigationController *login = [[LoginNavigationController alloc]init];\
[tabView presentViewController:login animated:YES completion:nil];\
}\
sucOK(pModel,success);\
} failture:^(NSError *error,NSString *strMsg) {\
if ([error.domain isEqual: NSURLErrorDomain]) {\
strMsg=@"网络错误";\
}\
err(error,strMsg);\
} ];\
}\

#define PMTASK_EXPORT_IMP_GET_h(name, returnType) \
+ (NSURLSessionDataTask *)name:(NSMutableDictionary *)dict success:(void(^)(returnType *response,BOOL success))sucOK failture:(void(^)(NSError *error,NSString *strDescription))err;\


#endif /* CommonNetwork_h */
